package com.atqar.utils;

//6个线程完成后才能执行主线程

import java.util.concurrent.CountDownLatch;

public class CountDownLathDemo {
    public static void main(String[] args) throws InterruptedException {

        //conutdownlatch的countdown方法全部执行完成后才会执行才会唤醒被await阻塞的线程

        //countdownlatch统计减1 参数必须大于0
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"线程执行完成");
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println("主线程开始执行");

    }
}


